package com.rizzo.analytics.domain.trend;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.joda.time.DateTime;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: jalie
 * Date: 11/23/12
 * Time: 10:12 PM
 * To change this template use File | Settings | File Templates.
 */
public class TrendPoint implements Serializable, Comparable<TrendPoint> {

	private static final long serialVersionUID = 13L;

	private DateTime timeStep;
	private double value;

	public TrendPoint() {
	}

	public TrendPoint(DateTime timeStep, double value) {
		this.timeStep = timeStep;
		this.value = value;
	}

	public DateTime getTimeStep() {
		return timeStep;
	}

	public void setTimeStep(DateTime timeStep) {
		this.timeStep = timeStep;
	}

	public double getValue() {
		return value;
	}

	public void setValue(double value) {
		this.value = value;
	}

	@Override
	public int compareTo(TrendPoint o) {
		if (o.getTimeStep().compareTo(this.getTimeStep()) == 0) {
			return Double.compare(o.getValue(), this.getValue());
		} else {
			return o.getTimeStep().compareTo(this.getTimeStep());
		}
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || getClass() != o.getClass()) {
			return false;
		}

		TrendPoint that = (TrendPoint) o;

		if (Double.compare(that.value, value) != 0) {
			return false;
		}
		if (!timeStep.isEqual(that.timeStep)) {
			return false;
		}

		return true;
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).
				append("timeStep", timeStep).
				append("value", value).
				toString();
	}
}

